<!DOCTYPE html>
<html class="x-admin-sm">

<head>
     <meta charset="UTF-8">
     <title>客户添加</title>
     <meta name="renderer" content="webkit">
     <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
     <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
     <link rel="stylesheet" href="css/font.css">
     <link rel="stylesheet" href="css/xadmin.css">
     <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
     <script type="text/javascript" src="lib/layui/layui.js" charset="utf-8"></script>
     <script type="text/javascript" src="js/address.js"></script>
     <script type="text/javascript" src="js/xadmin.js"></script>
     <script type="text/javascript" src="js/cookie.js"></script>
</head>

<body>
<script>
    $(function () {
        $("#add").click(function (){
            var name=$("#L_name").val();
            var telcode=$("#L_telCode").val();
            var department=$("#L_department").val();
            var regioncode=$("#L_regionCode").val();
            var myAddress=$("#L_address").val();
            var postcode=$("#L_postCode").val();

            $.ajax({
                url: address + "customer/add",
                type: "post",
                dataType: "JSON",
                contentType : "application/json; charset=utf-8",
                data: JSON.stringify({"name":name,"telCode":telcode,"department":department,
                    "regionCode":regioncode,"address":myAddress,"postCode":postcode}),
                success : function(data) {
                    layer.msg('已添加!',{icon:1,time:1000});
                    x_admin_father_reload();
                    x_admin_close();
                },
                error : function() {
                    alert("error");
                }
            });
        });
    });
</script>
<div class="x-body">
     <form class="layui-form">
          <div class="layui-form-item">
               <label for="L_name" class="layui-form-label">
                    <span class="x-red">*</span>姓名
               </label>
               <div class="layui-input-inline">
                    <input type="text" id="L_name" name="name" required="" lay-verify="name" autocomplete="off" class="layui-input">
               </div>
          </div>
          <div class="layui-form-item">
               <label for="L_telCode" class="layui-form-label">
                    <span class="x-red">*</span>电话
               </label>
               <div class="layui-input-inline">
                    <input type="text" id="L_telCode" name="telCode" required="" lay-verify="telCode" autocomplete="off" class="layui-input">
               </div>
          </div>
          <div class="layui-form-item">
               <label for="L_department" class="layui-form-label">
                    <span class="x-red">*</span>工作单位
               </label>
               <div class="layui-input-inline">
                    <input type="text" id="L_department" name="department" required="department" lay-verify="department" autocomplete="off" class="layui-input">
               </div>
          </div>
          <div class="layui-form-item">
               <label for="L_regionCode" class="layui-form-label">
                    <span class="x-red">*</span>地区编码
               </label>
               <div class="layui-input-inline">
                    <input type="text" id="L_regionCode" name="regionCode" required="regionCode" lay-verify="regionCode" autocomplete="off" class="layui-input">
               </div>
          </div>
          <div class="layui-form-item">
               <label for="L_address" class="layui-form-label">
                    <span class="x-red">*</span>住址
               </label>
               <div class="layui-input-inline">
                    <input type="text" id="L_address" name="address" required="address" lay-verify="address" autocomplete="off" class="layui-input">
               </div>
          </div>
          <div class="layui-form-item">
               <label for="L_postCode" class="layui-form-label">
                    <span class="x-red">*</span>邮政编码
               </label>
               <div class="layui-input-inline">
                    <input type="text" id="L_postCode" name="postCode" required="postCode" lay-verify="postCode" autocomplete="off" class="layui-input">
               </div>
          </div>
          <div class="layui-form-item">
               <label class="layui-form-label"></label>
               <button  class="layui-btn" id="add" lay-filter="add" lay-submit="">添加</button>
          </div>
     </form>
</div>
<script>
    layui.use(['form','layer'], function(){
        $ = layui.jquery;
        var form = layui.form,layer = layui.layer;
        //自定义验证规则
        form.verify({
            name: function(value){
                if(value === '' || value === null){
                    return '姓名不能为空';
                }
            }
            ,telCode: function(value){
                if(value === '' || value === null){
                    return '电话不能为空';
                }
            }
            ,department: function(value){
                if(value === '' || value === null){
                    return '工作单位不能为空';
                }
            }
            ,regionCode: function(value){
                if(value === '' || value === null){
                    return '地区不能为空';
                }
            }
            ,address: function(value){
                if(value === '' || value === null){
                    return '地址不能为空';
                }
            }
            ,postCode: function(value){
                if(value === '' || value === null){
                    return '邮政编码不能为空';
                }
            }
        });
        //监听提交
        form.on('submit(add)', function(data){
            console.log(data);
            //发异步，把数据提交给php
            layer.alert("增加成功", {icon: 6},function () {
                //关闭当前frame
                x_admin_close();

                // 可以对父窗口进行刷新
                x_admin_father_reload();
            });
            return false;
        });
    });
</script>
</body>

</html>